/**
 * 会员抽奖验证
 * author: weiki
 * datetime: 2017/10/13
 */
const app = getApp()

Page({
  data: {
    showHint: false,
    success: true,
    goodsId: 0,
    regimentId: 0,
    groupType: 0
  },

  onLoad: function (options) {
    this.setData({
      goodsId: options.id,
      regimentId: options.regiment_id,
      groupType: options.group_type
    });
  },


  //提交按钮
  formSubmit: function (e) {
    var that = this;
    var group_type = that.data.groupType;
    console.log(group_type);
    var phoneNum = e.detail.value.phone.trim();
    if (phoneNum.length == 11) {

      wx.request({
        url: app.url + "api_team/memberVerifyV1",
        header: {
          'content-type': 'application/json',
          'token': wx.getStorageSync('token_key')
        },
        data: {
          mobile: phoneNum
        },
        success: function (res) {
          if (res.data.result.errcode == 0) {
              setTimeout(function () {
                wx.redirectTo({
                  url: '/pages/group/groupdetail/index?id=' + that.data.goodsId +
                  '&regiment_id=' + that.data.regimentId + '&group_type=' + group_type + '&verify=1',
                })
              }, 2000);
          } else {
            var orderList = res.data.result.order_list;
            console.log(res.data.result.order_list);
            var totalMoney = 0;
            for (var i = 0; i < orderList.length; i++) {
              if (orderList[i].money_paid != null) {
                totalMoney += parseFloat(orderList[i].money_paid);
              }
            }
            if (totalMoney > 59) {
              wx.showToast({
                title: '验证成功',
              });
              setTimeout(function () {
                wx.redirectTo({
                  url: '/pages/group/groupdetail/index?id=' + that.data.goodsId +
                  '&regiment_id=' + that.data.regimentId + '&group_type=' + group_type + '&verify=1',
                })
                // if (group_type == 4) {
                // 	wx.redirectTo({
                // 		url: '/pages/group/groupdetail/index?id=' + that.data.goodsId +
                // 		'&regiment_id=' + that.data.regimentId + '&group_type=4&verify=1',
                // 	})
                // } else {
                // 	wx.redirectTo({
                // 		url: '/pages/group/groupdetail/index?id=' + that.data.goodsId +
                // 		'&regiment_id=' + that.data.regimentId + '&group_type=3&verify=1',
                // 	})
                // }
              }, 2000);
            } else {
              that.setData({
                success: false
              });
              setTimeout(function () {
                wx.redirectTo({
                  url: '/pages/group/lottery/lottery',
                })
              }, 2500);
            }
          }
        }
      })
    } else {
      this.setData({
        showHint: true
      });
    }
  },
})